package com.cykj.v_m_sprintboot.controller;

import com.cykj.v_m_sprintboot.bean.PageInf;
import com.cykj.v_m_sprintboot.bean.TbVmi;
import com.cykj.v_m_sprintboot.bean.Yys;

import com.cykj.v_m_sprintboot.service.TbVmiService;
import org.apache.ibatis.session.RowBounds;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class VendingMachine {
    @Autowired
    public TbVmiService tbvmiService;
    @RequestMapping("/VM")
    @ResponseBody
    public Map<String,Object> VM(@RequestBody PageInf pageInf){
        System.out.println("当前页："+pageInf.getPage()+",几条数据为一页："+pageInf.getSize());
        RowBounds row =new RowBounds((pageInf.getPage()-1)*pageInf.getSize(),pageInf.getSize());
        List<TbVmi> vmiList = tbvmiService.VM();
        System.out.println(vmiList.size());
        Map<String,Object> map=new HashMap<>();
        map.put("count",tbvmiService.count(1));
        map.put("vmiList",vmiList);
        return map;
    }
    @RequestMapping("/vmcx")
    @ResponseBody
    public Map<String,Object> vmcx(@RequestBody PageInf pageInf,@RequestBody TbVmi tbVmi){
        System.out.println(tbVmi.getVmState()+tbVmi.getVmSite()+"+++++++");
        System.out.println("当前页："+pageInf.getPage()+",几条数据为一页："+pageInf.getSize());
        RowBounds row =new RowBounds((pageInf.getPage()-1)*pageInf.getSize(),pageInf.getSize());
        String vmstate=tbVmi.getVmState();
        String vmsite=tbVmi.getVmSite();
        List<TbVmi> tbVmiList = tbvmiService.vmcx(vmstate,vmsite);
        System.out.println(tbVmiList.size());
        Map<String,Object> map=new HashMap<>();
        map.put("count",tbvmiService.count(1));
        map.put("tbVmiList",tbVmiList);
        return map;
    }
    @RequestMapping("/getyys")
    @ResponseBody
    public boolean getyys(@RequestBody Yys yys ){
        System.out.println(yys.getTime1()+yys.getTime2()+yys.getVmSite()+yys.getName());
        String str =yys.getVmSite();
        System.out.println(str);
        String time = yys.getTime1().concat("-"+yys.getTime2());
        boolean a =(tbvmiService.sqvm(time,str,yys.getName(),yys.getCoordinate()));
        return a;
    }
    @RequestMapping("/vmjy")
    @ResponseBody
    public boolean vmjy(@RequestBody TbVmi tbVmi){
        System.out.println(tbVmi.getVmid());
        boolean jy= tbvmiService.vmjy((int) tbVmi.getVmid());
        return jy;
    }
    @RequestMapping("/vmqy")
    @ResponseBody
    public boolean vmqy(@RequestBody TbVmi tbVmi){
        System.out.println(tbVmi.getVmid());
        boolean jy= tbvmiService.vmqy((int) tbVmi.getVmid());
        return jy;
    }
}
